package bookshelf.client;


import bookshelf.client.author.AuthorList;
import bookshelf.client.book.BookController;
import bookshelf.client.book.BookDetail;
import bookshelf.client.book.BookList;

import com.google.gwt.core.client.EntryPoint;
//import com.google.gwt.core.client.GWT;
//import com.google.gwt.event.dom.client.ClickEvent;
//import com.google.gwt.event.dom.client.ClickHandler;
//import com.google.gwt.event.dom.client.KeyCodes;
//import com.google.gwt.event.dom.client.KeyUpEvent;
//import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.Window;
//import com.google.gwt.user.client.rpc.AsyncCallback;
//import com.google.gwt.user.client.ui.Button;
//import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TabPanel;
//import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Bookshelf implements EntryPoint, ResizeHandler {

	private static Bookshelf bookshelf;
	private DockPanel outer;

//	private TopPanel topPanel = new TopPanel(null);
	private VerticalPanel topPanel = new VerticalPanel();

	private VerticalPanel rightPanel = new VerticalPanel();
	private BookController bc;
	private BookList booklist;
	private BookDetail bookdetail;
	
	private TabPanel t_panel =  new TabPanel();
	private VerticalPanel authorlist_panel = new VerticalPanel();
	private VerticalPanel publisher_panel = new VerticalPanel();

	private VerticalPanel leftPanel = new VerticalPanel();
	private LeftMenu menu;

	public static Bookshelf getSingleton() {
		return bookshelf;
	}

	@Override
	public void onModuleLoad() {
		// TODO Auto-generated method stub
		bookshelf = this;

		//トップパネル
		
	    topPanel.setWidth("100%");
	    HTML tmphtml = new HTML();
	    tmphtml.setHTML("本棚Project");
	    topPanel.add(tmphtml);

	    
	    bc = BookController.getBookController();
	    //データ表示部（一覧）
		booklist = new BookList();
		booklist.setWidth("100%");
		booklist.setBookController(bc);
		bc.setBookList(booklist);

	    //データ表示部（詳細）
		bookdetail = new BookDetail();
		bookdetail.setBookController(bc);
		bc.setBookDetail(bookdetail);

		rightPanel.add(booklist);
		rightPanel.add(bookdetail);
		
		//タブパネルの設定
		t_panel.add(rightPanel, "本のリスト");

//		authorlist_panel.add(new Label("著者一覧予定地"));
		authorlist_panel.add(new AuthorList());
		t_panel.add(authorlist_panel, "著者一覧");

		publisher_panel.add(new Label("出版社一覧予定地"));
		t_panel.add(publisher_panel, "出版社一覧");
		
		t_panel.setAnimationEnabled(true);
		//初期表示のタブを指定
		t_panel.selectTab(0);
		

		//メニュー部
		menu = new LeftMenu();
		leftPanel.add(menu);
		menu.setWidth("100%");

		//外枠
		outer = new DockPanel();
		outer.add(topPanel, DockPanel.NORTH);
		outer.add(menu, DockPanel.WEST);
//		outer.add(rightPanel, DockPanel.CENTER);
		outer.add(t_panel, DockPanel.CENTER);
		outer.setWidth("100%");

		outer.setSpacing(4);
//		outer.setCellWidth(rightPanel, "100%");
		outer.setCellWidth(t_panel, "100%");

		// HTML txt= new HTML();
		// txt.setHTML("test");
		// rightPanel.add(txt);

		Window.addResizeHandler(this);

		Window.enableScrolling(false);
		Window.setMargin("0px");

		RootPanel.get().add(outer);

		DeferredCommand.addCommand(new Command() {
			public void execute() {
				onWindowResized(Window.getClientWidth(), Window
						.getClientHeight());
			}
		});

		onWindowResized(Window.getClientWidth(), Window.getClientHeight());

	}

	@Override
	public void onResize(ResizeEvent event) {
		// TODO Auto-generated method stub
		onWindowResized(event.getWidth(), event.getHeight());
	}

	public void onWindowResized(int width, int height) {

	}
}
